package com.authstr.fitness_room_manage.service.impl;


import cn.hutool.core.util.StrUtil;
import com.authstr.basic.exception.Assert;
import com.authstr.basic.exception.BaseExceptionEnum;
import com.authstr.basic.reqres.request.RequestPara;
import com.authstr.basic.reqres.utils.WebUtils;
import com.authstr.basic.web.service.BaseServiceImpl;
import com.authstr.fitness_room_manage.mapper.inter.JsfMemberDao;
import com.authstr.fitness_room_manage.service.inter.JsfMemberService;
import com.authstr.model.base.BaseDepartment;
import com.authstr.model.constant.BaseC;
import com.authstr.model.jsf.JsfEmployeeInfo;
import com.authstr.model.jsf.JsfMemberInfo;
import com.authstr.model.utils.ModelUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;


@Service
public class JsfMemberServiceImpl extends BaseServiceImpl<JsfMemberDao, JsfMemberInfo> implements JsfMemberService {

    @Autowired
    JsfMemberDao jsfMemberDao;

    @Override
    public Page query(@Param("page") Page page) {
        return jsfMemberDao.query(page, WebUtils.getInteger("type"),WebUtils.get("name_or_number"));
    }

    @Override
    public List<Map> getAll(RequestPara para){
        return jsfMemberDao.getAll(para.get("name"),para.get("exclude_id"));
    };

    /**
     * 添加或编辑
     * @param model
     */
    @Transactional(rollbackFor=Exception.class)
    @Override
    public Long addOrEdit(JsfMemberInfo model) {
        Assert.isTrue(super.isUnique(model,"name"),"会员名称不能重复");
        Assert.isTrue(super.isUnique(model,"card_number"),"会员卡号不能重复");
        //设置状态为正常
        if(ModelUtil.isNew(model)){
            model.setStatus(BaseC.COMMON_STATUS_NORMAL);
            //创建账号

        }
        super.saveOrUpdate(model);
        return model.getId();
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public String setMemberUserId(String id, Long user_id){
        JsfMemberInfo model=super.getById(id);
        Assert.isTrue(model!=null,"错误的id");
        if(user_id==null){
            super.updateToNull(model,"user_id");
        }else{
            model.setUser_id(user_id);
            super.updateById(model);
        }
        return "会员成功绑定用户";
    }


    /**
     * 设置一个单位的parent_ids属性和level属性
     * @param model
     */
    public void setParentIds(BaseDepartment model){
    }

    /**
     * 在修改后,更新所有子单位的结构
     * @param oldDepartment
     * @param newDepartment
     */
    public void updataAllChildParentIdsForEdit(BaseDepartment oldDepartment, BaseDepartment newDepartment){
    }

    /**
     *在删除后,修改子单位的继承关系和层级
     * @param byDelete 被删除的单位
     */
    public void updataAllChildParentIdsForDelete(BaseDepartment byDelete){
    }

    /**
     * 在删除后,删除子单位
     * @param byDelete 被删除的单位
     */
    public void deleteAllChild(BaseDepartment byDelete){
    }

    /**
     * 删除（不包括子单位）
     * @param ids
     */
    @Transactional(rollbackFor=Exception.class)
    @Override
    public void delete(Long[] ids){
    }

    /**
     * 删除,包括子单位
     * @param ids
     */
    @Transactional(rollbackFor=Exception.class)
    @Override
    public void deleteChildren(Long[] ids){
    }
    


}
